{ Statement: http://informatics.mccme.ru/moodle/mod/statements/view3.php?chapterid=763
  Verdict: Accepted
}
uses
	SysUtils, Math;
 
const
	INF:longint = maxlongint;
 
type
	node = record
		v:longint;
		l,r:longint;
	end;
 
var
	i,n,k,cc,pp:longint;
	a:array[0..100010] of node;
	d,p:array[0..100010] of longint;
 
 
function search(v:longint):longint;
 
var
	i:longint;
 
begin
result := 0;
i := 1;
while i <= cc do begin
	if i <> INF then result := i;
	if v = a[i].v then exit;
	if v > a[i].v then i := a[i].r else i := a[i].l;
end;
end;
 
procedure add(v:longint);
 
var
	t:longint;
 
begin
t := search(v);
if a[t].v = v then exit;
inc(cc);
a[cc].v := v;
a[cc].l := INF;
a[cc].r := INF;
if v > a[t].v then a[t].r := cc else a[t].l := cc;
end;
 
function height(n:longint):longint;
 
var
	t,k:longint;
 
begin
if a[n].l <> INF then k := height(a[n].l) else k := 0;
if a[n].r <> INF then t := height(a[n].r) else t := 0;
result := max(k, t) + 1;
end;
 
procedure sort(l,r:longint);
 
var
	i,j,x,y:longint;
 
begin
i := l;
j := r;
x := p[(l + r) shr 1];
repeat
	while p[i] < x do inc(i);
	while p[j] > x do dec(j);
	if i <= j then begin
		y := p[i];
		p[i] := p[j];
		p[j] := y;
		inc(i);
		dec(j);
	end;
until i > j;
if l < j then sort(l, j);
if i < r then sort(i, r);
end;
 
begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(k);
n := 0;
while k <> 0 do begin
	inc(n);
	d[n] := k;
	read(k);
end;
cc := 0;
for i := 1 to n do
	add(d[i]);
pp := 0;
for i := 1 to cc do
	if byte(a[i].l <> INF) + byte(a[i].r <> INF) = 1 then begin
		inc(pp);
		p[pp] := a[i].v;
	end;
sort(1, pp);
for i := 1 to pp do
	write(p[i],' ');
end.